package com.example.base.system.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.base.app.App;
import com.example.base.app.AppUtils;
import com.example.base.excetion.GlobalExcetion;
import com.example.base.springboot.DynamicLoad;
import com.example.base.system.SysAppService;
import com.example.base.system.domain.SysApp;
import com.example.base.system.service.SysApiService;
import com.example.base.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Api(tags = "系统摸块")
@RestController
@RequestMapping("system")
public class SystemController {

    @Autowired
    private DynamicLoad dynamicLoad;

    @Autowired
    private SysAppService sysAppService;

    @GetMapping("version")
    public JSONObject getSystemInfo(){
        String str="{\"code\":200,\"data\":\"1.6.9\",\"message\":\"\"}";
        JSONObject object=JSONObject.parseObject(str);
        return object;
    }

    @ApiOperation("卸载jar包")
    @GetMapping("unrefjar")
    public JSONObject unrefJarController(@RequestParam("appName")String appName) throws GlobalExcetion {
        if(appName.equals(AppUtils.SYSTEM_MAIN_APP)){
            throw new GlobalExcetion(1,"应用名称不得为系统应用app");
        }
        SysApp app=sysAppService.getSysAppByAppName(appName);
        if(app==null){
            throw new GlobalExcetion(1,"应用app不存在");
        }
        //dynamicLoad.unrefApp(app);
        return Result.successInfo("卸载成功");
    }
}
